import subprocess

# 运行外部命令
result = subprocess.run(["ping", "-c", "4", "8.8.8.8"], capture_output=True, text=True)

# 检查返回状态
if result.returncode == 0:
    print("命令执行成功！")
    print("输出：")
    print(result.stdout)
else:
    print("命令执行失败！")
    print("错误信息：")
    print(result.stderr)